﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Model;

namespace DAL
{
   public class AddressDAL
    {
        DBHelper db = new DBHelper();
        public List<Address> auctions()
        {
            string sqlShow = "select AddressID, AddressCategory from [dbo].[Address]";
            List<Address> list = null;
            DataTable dt = db.GetData(sqlShow);
            if (dt.Rows.Count > 0)
            {
                list = new List<Address>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Address ac = new Address();
                    ac.AddressID = Convert.ToInt32(dt.Rows[i]["AddressID"]);
                    ac.AddressCategory = dt.Rows[i]["AddressCategory"].ToString();
                    list.Add(ac);
                }
            }
            return list;
        }
        public bool AddTian(Address ad)
        {
            string SqlTian = $"insert into [dbo].[Address]([AddressCategory]) values('{ad.AddressCategory}')";
            if (db.SetData(SqlTian))
            {
                return true;
            }
            return false;
        }
    }
}
